// $(document).ready(function () {

    $("#jqGrid").jqGrid({
        url: select_url + 'device',
        editurl: edit_url + 'device',
        mtype: 'POST',
        datatype: "json",
        colModel: [
            {
                label: '序号',
                name: 'id',
                width: 50,
                key: true,
                editable: false,
                editrules : { required: true},
                hidden: true
            },
            {
                label: '客户名称',
                name: 'clientname',
                width: 120,
                editable: true
            },
            {
                label : '设备名称',
                name: 'devicename',
                width: 130,
                editable: true
            },
            {
                label: '仪表编号',
                name: 'deviceid',
                width: 100,
                editable: true
            },
            {
                label : 'SIM卡号码',
                name: 'sim',
                width: 130,
                editable: true
            },
            {
                label: '注册状态',
                name: 'register',
                width: 80,
                editable: true,
                edittype:'select',formatter:'select',
                editoptions : {
                    value:"1 : 已注册; 0 : 未注册"
                }
            },
            {
                label: '设备锁定',
                name: 'lockdevice',
                width: 80,
                editable: true,
                edittype:'select',formatter:'select',
                editoptions : {
                    value:"1 : 锁定; 0 : 未锁定"
                }
            },
            {
                label : '所属区域',
                name: 'zone',
                width: 100,
                editable: true
            },
            {
                label: '地理位置',
                name: 'pos',
                width: 170,
                editable: true
            },
            {
                label: '测点分布',
                name: 'cdfb',
                width: 80,
                editable: false,
                formatter: function(cellvalue, options, rowObject){
                    var html="<a href=\'#\' data-toggle=\'modal\' data-id=\'"+rowObject.id+"\' data-target=\'#PointsDistributeModal\'><span class=\'icon icon-graph-pie\'></span>测点</a>";
                    return html;
                }
            },
            {
                label: '报警开关',
                name: 'bjkg',
                width: 80,
                editable: true,
                edittype:'select',formatter : 'select',
                editoptions : {
                    value:"1 : 开启; 0 : 关闭"
                }
            },
            {
                label: '参数修改',
                width: 80,
                editable: false,
                formatter: function(cellvalue, options, rowObject){
                    var html="<a href=\'#\' data-toggle=\'modal\' data-id=\'"+rowObject.id+"\' data-target=\'#parameterModal\'><span class=\'icon icon-gear\'></span>参数</a>";
                    return html;
                }
            },
            {//行编辑
                label: "操作",
                name: "actions",
                width: 100,
                formatter: "actions",
                formatoptions: {
                    keys: true,
                    editOptions: {},
                    addOptions: {},
                    delOptions: {}
                }       
            }
        ],

        jsonReader: {
            root: 'rows',
            repeatitems : false,
            id: "0"
        },
        rowNum:10,
        rowList:[10,20,30],
        sortname: 'id',
        sortorder : 'desc',//倒序
        viewrecords: true,
        styleUI : 'Bootstrap',
        rownumbers: true, //行序号
        rownumWidth: 25,
        multiselect: true,//复选框
        width: 1000,
        height: 350,
        pager: "#jqGridPager",
        shrinkToFit: false //每列的宽度不会成比例缩放，而是保持原有设置，出现水平滚动条

    });


    var template = "<div style='margin-left:15px;'><div> 客户名称 <sup>*</sup>:</div><div>{clientname} </div>";
    template += "<div> 设备名称: </div><div>{devicename} </div>";
    template += "<div> 仪表编号:</div><div> {deviceid} </div>";
    template += "<div> SIM卡号码: </div><div>{sim} </div>";
    template += "<div> 注册状态: </div><div>{register} </div>";
    template += "<div> 锁定设备: </div><div>{lockdevice} </div>";
    template += "<div> 所属区域:</div><div> {zone} </div>";
    template += "<div> 地理位置:</div><div> {pos} </div>";
    template += "<div> 测点分布:</div><div> {cdfb} </div>";
    template += "<div> 报警开关:</div><div> {bjkg} </div>";
    template += "<hr style='width:100%;'/>";
    template += "<div> {sData} {cData}  </div></div>";

    

    $('#jqGrid').navGrid('#jqGridPager',
        // the buttons to appear on the toolbar of the grid
        { edit: true, add: true, del: true, search: false, refresh: true, view: false, position: "left", cloneToTop: false },
        // Edit Dialog
        {
            editCaption: "修改设备信息",
        },
        // Add Dialog
        {
            addCaption: "添加设备信息",
        }
    );

    //查询
    var client_mask = $("#s_clientname").val();
    var deviceid_mask = $("#s_deviceid").val();
    // var sim_mask = $("#s_sim").val();
    gridReload("device?clientname="+client_mask+"&deviceid="+deviceid_mask);

    // jQuery("#jqGrid").navButtonAdd('#jqGridPager',{
    //    caption:"Excel", 
    //    buttonicon:"glyphicon-icon-excel", 
    //    onClickButton: function(){ 
    //       alert("导出excel");
    //    }, 
    //    position:"last"
    // })
// });